<?php
namespace common\models;


class EthTradeLog extends BaseModel
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'eth_trade_log';
    }


    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['member_id', 'create_time', 'update_time'], 'integer'],
            [['data'], 'string'],
            [['block_hash', 'hash'], 'string', 'max' => 128],
            [['from_address', 'to_address'], 'string', 'max' => 64],
            [['type', 'status', 'value', 'block_number', 'nonce'], 'safe'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'member_id' => '会员ID',
            'type' => '1 USDT 2 BCO',
            'block_hash' => '区块hash',
            'block_number' => '区块高度（id）',
            'from_address' => '来源地址',
            'to_address' => '收款地址',
            'hash' => '哈希值',
            'value' => '数量',
            'nonce' => 'Nonce',
            'data' => '源数据',
            'status' => '0待处理 1已处理',
            'create_time' => 'Create Time',
            'update_time' => 'Update Time',
        ];
    }    

	/*
		* 数据列表
		* whereArr 条件
		* params 基本参数 包含 field order page limit
		* extends  扩展信息 一些相关的信息
		* 
	*/	
	public static function dataList($whereArr, $params, $extends = array())
	{
		$model  = self::find();
		$where  = isset($whereArr['where']) ? $whereArr['where'] : [];
		$whereAnd = isset($whereArr['and'])?$whereArr['and']:[];
		$models = self::queryFormart($model,$where,$params,$whereAnd);
		$model  = $models['model'];
		
		$data  = $model->asarray()->all();
		if(!$data) return array();

		//扩展信息
		if(!$extends) return $data;
		foreach ($data as $k=>&$v) {
		    $v['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
		    $v['text']        = '充值';
            foreach ($extends as $extend) {

            }
        }

		return $data;	
	}

	public static function getOne($where, $field = ['*'])
	{
		return self::find()->select($field)->where($where)->asarray()->one();
	}


	public static function getAll($where = [], $field = ['*'])
	{
		return self::find()->select($field)->where($where)->asarray()->all();
	}

    /*
        * 充值列表
        * whereArr 条件
        * params 基本参数 包含 field order page limit
        * extends  扩展信息 一些相关的信息
        *
    */
    public static function rechargeList($whereArr,$params,$extends=array())
    {
        $model  = self::find();
        $where  = $whereArr['where'];
        $whereAnd = isset($whereArr['and'])?$whereArr['and']:[];
        $models = self::queryFormart($model,$where,$params,$whereAnd);
        $model  = $models['model'];
        self::$pages = $models['pages'];

        $data  = $model->asarray()->all();
        if(!$data) return array();

        //扩展信息
        if(!$extends) return $data;
        return $data;
    }

}